package com.fulin.sycnLife;

import java.util.concurrent.TimeUnit;

public class Interrupted {
	public static void main(String[] args) throws Exception{
		
		//休眠线程
		Thread sleepThread = new Thread(new SleepRunner(),"SleepThread");
		sleepThread.setDaemon(true);
		
		//忙碌线程
		Thread busyThread = new Thread(new BusyRunner(),"BusyThread");
		busyThread.setDaemon(true);
		
		sleepThread.start();
		busyThread.start();
		TimeUnit.SECONDS.sleep(5);
		
		sleepThread.interrupt();
		busyThread.interrupt();
		System.out.println("SleepThread interrupted is "+sleepThread.isInterrupted());
		System.out.println("BusyThread interrupted is "+busyThread.isInterrupted());
		SleepUtils.second(2);
	}
	
	//一直休眠的线程
	static class SleepRunner implements Runnable{

		@Override
		public void run() {
			while(true){
				SleepUtils.second(10);
			}
		}
		
	}
	
	//一直忙碌的线程
	static class BusyRunner implements Runnable{

		@Override
		public void run() {
			while(true){}
		}
		
	}
}
